<?php
namespace App\Http\Controllers\Admin;

use App\Http\Classes\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\Classes\Log;
/**
 * Created by PhpStorm.
 * User: Celebration-Grey
 * Date: 2017/5/7
 * Time: 13:12
 */
class AdminController extends Controller
{
    public function adminRegister(Request $request){

    }

    public function adminLogin(Request $request){
        try{
            $dataArray = $request->all();
            $dataArray = Admin::adminLogin($dataArray);
            if($dataArray){
                session(['admin' => $dataArray]);
                return $this->response(200,'登录成功',null);
            }
            else{
                return $this->response(304,'用户名与密码不匹配',null);
            }
        }
        catch (\Exception $exception){
            Log::adminError(__FUNCTION__,$exception->getCode(),$exception->getMessage(),$exception->getFile(),$exception->getLine(), 0);
            return $this->response(500,"系统内部错误！".$exception->getMessage(),null);
        }
    }

    private function response($status,$message,$data){
        $response = [];
        $response['status'] = $status;
        $response['message'] = $message;
        $response['data'] = $data;
        return response()->json($response);
    }
}